import logging

from logging import FileHandler


def init_app(app, logger=None):

    formatter = logging.Formatter(
        '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s')
    handler = FileHandler(app.config['LOGGER_PATH'])
    logger_level = getattr(logging,
                           app.config['LOGGER_LEVEL'].upper(),
                           logging.DEBUG)
    handler.setLevel(logger_level)
    handler.setFormatter(formatter)

    if logger is None:
        logger = app.logger
    logger.addHandler(handler)
    logger.setLevel(logger_level)
